﻿@inject IContactFilters Filters

<button class="btn btn-primary"
        disabled="@Filters.Loading"
        @onclick="ToggleAsync">
    @Label
</button>
&nbsp;
@code {

    /// <summary>
    /// Button text based on current state.
    /// </summary>
    private string Label => Filters.ShowFirstNameFirst ?
    "Show Last Name, First Name" :
    "Show First Name, Last Name";

    /// <summary>
    /// Reference to the <see cref="GridWrapper"/>.
    /// </summary>
    [CascadingParameter]
    public GridWrapper GridWrapper { get; set; }

    /// <summary>
    /// Toggle name preference.
    /// </summary>
    /// <returns>A <see cref="Task"/>.</returns>
    private Task ToggleAsync()
    {
        Filters.ShowFirstNameFirst = !Filters.ShowFirstNameFirst;
        return GridWrapper.FilterChanged.InvokeAsync(this);
    }
}
